const stk = document.querySelector('#textdiv>textarea').value.split('\n');
let is = 0;
let nowType = 3;
let res = '使用完了记得刷新';
const testType = ['!test!\n!\n\n\n', '!test!\n\n'];
let s = '';
stk.reverse();
/**
 * Get the scores of a name.
 */
function chk() {
  if (is === 0) {
    if (nowType === 3) {
      console.log(res);
      nowType = 1;
      if (stk.length !== 0) {
        s = stk[stk.length - 1];
        while (s === '') {
          stk.pop();
          s = stk[stk.length - 1];
        }
        res = `| ${s} | `;
        document.querySelector('#textdiv>textarea').value = testType[parseInt(
            nowType / 2)] + s;
        document.querySelector('.goBtn').click();
        is = 1;
        stk.pop();
      } else {
        alert('测试已完成');
        clearInterval(si);
      }
    } else {
      if (nowType % 2 === 1) {
        document.querySelector('#textdiv>textarea').value =
          `${testType[parseInt(nowType / 2)]}${s}\n${s}`;
      } else {
        document.querySelector('#textdiv>textarea').value =
          `${testType[parseInt(nowType / 2)]}${s}`;
      }
      document.querySelector('.goBtn').click();
      is = 1;
      nowType++;
    }
  } else {
    const a = cw().document.querySelectorAll('span.u');
    const n = a.length;
    let kkk = 0;
    let loc;
    if (n > 100) {
      for (let i = 100; i < n; i++) {
        if (cw().document.querySelectorAll('span.u')[i].textContent.split(' ')[
            0] === '》') {
          kkk = 1;
          loc = i;
          break;
        }
      }
    }
    if (kkk) {
      res += cw().document.querySelectorAll('span.u')[loc].textContent.split(
          ' ')[2] + ' | ';
      is = 0;
    }
  }
}
const si = setInterval(function() {
  chk();
}, 1000);